<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class Object - RDoc Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0-preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-Object-label-What-27s+Here">What’s Here</a>
    <li><a href="#class-Object-label-Querying">Querying</a>
    <li><a href="#class-Object-label-Instance+Variables">Instance Variables</a>
    <li><a href="#class-Object-label-Other">Other</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="BasicObject.html">BasicObject</a>
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><a class="include" href="Kernel.html">Kernel</a>
  </ul>
</div>

        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-i-21~">#!~</a>
    <li ><a href="#method-i-3C-3D-3E">#&lt;=&gt;</a>
    <li ><a href="#method-i-3D-3D-3D">#===</a>
    <li ><a href="#method-i-define_singleton_method">#define_singleton_method</a>
    <li ><a href="#method-i-display">#display</a>
    <li ><a href="#method-i-dup">#dup</a>
    <li ><a href="#method-i-enum_for">#enum_for</a>
    <li ><a href="#method-i-eql-3F">#eql?</a>
    <li ><a href="#method-i-extend">#extend</a>
    <li ><a href="#method-i-freeze">#freeze</a>
    <li ><a href="#method-i-hash">#hash</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-instance_of-3F">#instance_of?</a>
    <li ><a href="#method-i-instance_variable_defined-3F">#instance_variable_defined?</a>
    <li ><a href="#method-i-instance_variable_get">#instance_variable_get</a>
    <li ><a href="#method-i-instance_variable_set">#instance_variable_set</a>
    <li ><a href="#method-i-instance_variables">#instance_variables</a>
    <li ><a href="#method-i-is_a-3F">#is_a?</a>
    <li ><a href="#method-i-itself">#itself</a>
    <li ><a href="#method-i-kind_of-3F">#kind_of?</a>
    <li ><a href="#method-i-method">#method</a>
    <li ><a href="#method-i-methods">#methods</a>
    <li ><a href="#method-i-nil-3F">#nil?</a>
    <li ><a href="#method-i-object_id">#object_id</a>
    <li ><a href="#method-i-private_methods">#private_methods</a>
    <li ><a href="#method-i-protected_methods">#protected_methods</a>
    <li ><a href="#method-i-public_method">#public_method</a>
    <li ><a href="#method-i-public_methods">#public_methods</a>
    <li ><a href="#method-i-public_send">#public_send</a>
    <li ><a href="#method-i-remove_instance_variable">#remove_instance_variable</a>
    <li ><a href="#method-i-respond_to-3F">#respond_to?</a>
    <li ><a href="#method-i-respond_to_missing-3F">#respond_to_missing?</a>
    <li ><a href="#method-i-send">#send</a>
    <li ><a href="#method-i-singleton_class">#singleton_class</a>
    <li ><a href="#method-i-singleton_method">#singleton_method</a>
    <li ><a href="#method-i-singleton_methods">#singleton_methods</a>
    <li ><a href="#method-i-to_enum">#to_enum</a>
    <li ><a href="#method-i-to_s">#to_s</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-Object">
    <h1 id="class-Object" class="class">
      class Object
    </h1>

    <section class="description">
    
<p><a href="Object.html"><code>Object</code></a> is the default root of all Ruby objects.  <a href="Object.html"><code>Object</code></a> inherits from <a href="BasicObject.html"><code>BasicObject</code></a> which allows creating alternate object hierarchies.  Methods on <a href="Object.html"><code>Object</code></a> are available to all classes unless explicitly overridden.</p>

<p><a href="Object.html"><code>Object</code></a> mixes in the <a href="Kernel.html"><code>Kernel</code></a> module, making the built-in kernel functions globally accessible.  Although the instance methods of <a href="Object.html"><code>Object</code></a> are defined by the <a href="Kernel.html"><code>Kernel</code></a> module, we have chosen to document them here for clarity.</p>

<p>When referencing constants in classes inheriting from <a href="Object.html"><code>Object</code></a> you do not need to use the full namespace.  For example, referencing <code>File</code> inside <code>YourClass</code> will find the top-level <a href="File.html"><code>File</code></a> class.</p>

<p>In the descriptions of Object’s methods, the parameter <em>symbol</em> refers to a symbol, which is either a quoted string or a <a href="Symbol.html"><code>Symbol</code></a> (such as <code>:name</code>).</p>

<h2 id="class-Object-label-What-27s+Here">What’s Here<span><a href="#class-Object-label-What-27s+Here">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>First, what’s elsewhere. Class Object:</p>
<ul><li>
<p>Inherits from <a href="BasicObject.html#class-BasicObject-label-What-27s+Here">class BasicObject</a>.</p>
</li><li>
<p>Includes <a href="Kernel.html#module-Kernel-label-What-27s+Here">module Kernel</a>.</p>
</li></ul>

<p>Here, class Object provides methods for:</p>
<ul><li>
<p><a href="Object.html#class-Object-label-Querying">Querying</a></p>
</li><li>
<p><a href="Object.html#class-Object-label-Instance+Variables">Instance Variables</a></p>
</li><li>
<p><a href="Object.html#class-Object-label-Other">Other</a></p>
</li></ul>

<h3 id="class-Object-label-Querying">Querying<span><a href="#class-Object-label-Querying">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p>#!~: Returns <code>true</code> if <code>self</code> does not match the given object, otherwise <code>false</code>.</p>
</li><li>
<p>#&lt;=&gt;: Returns 0 if <code>self</code> and the given object <code>object</code> are the same object, or if <code>self == object</code>; otherwise returns <code>nil</code>.</p>
</li><li>
<p><a href="Object.html#method-i-3D-3D-3D"><code>===</code></a>: Implements case equality, effectively the same as calling <a href="BasicObject.html#method-i-3D-3D"><code>==</code></a>.</p>
</li><li>
<p><a href="Object.html#method-i-eql-3F"><code>eql?</code></a>: Implements hash equality, effectively the same as calling <a href="BasicObject.html#method-i-3D-3D"><code>==</code></a>.</p>
</li><li>
<p><a href="Object.html#method-i-kind_of-3F"><code>kind_of?</code></a> (aliased as <a href="Object.html#method-i-is_a-3F"><code>is_a?</code></a>): Returns whether given argument is an ancestor of the singleton class of <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-instance_of-3F"><code>instance_of?</code></a>: Returns whether <code>self</code> is an instance of the given class.</p>
</li><li>
<p><a href="Object.html#method-i-instance_variable_defined-3F"><code>instance_variable_defined?</code></a>: Returns whether the given instance variable is defined in <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-method"><code>method</code></a>: Returns the <a href="Method.html"><code>Method</code></a> object for the given method in <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-methods"><code>methods</code></a>: Returns an array of symbol names of public and protected methods in <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-nil-3F"><code>nil?</code></a>: Returns <code>false</code>. (Only <code>nil</code> responds <code>true</code> to method <code>nil?</code>.)</p>
</li><li>
<p><a href="Object.html#method-i-object_id"><code>object_id</code></a>: Returns an integer corresponding to <code>self</code> that is unique for the current process</p>
</li><li>
<p><a href="Object.html#method-i-private_methods"><code>private_methods</code></a>: Returns an array of the symbol names of the private methods in <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-protected_methods"><code>protected_methods</code></a>: Returns an array of the symbol names of the protected methods in <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-public_method"><code>public_method</code></a>: Returns the <a href="Method.html"><code>Method</code></a> object for the given public method in <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-public_methods"><code>public_methods</code></a>: Returns an array of the symbol names of the public methods in <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-respond_to-3F"><code>respond_to?</code></a>: Returns whether <code>self</code> responds to the given method.</p>
</li><li>
<p><a href="Object.html#method-i-singleton_class"><code>singleton_class</code></a>: Returns the singleton class of <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-singleton_method"><code>singleton_method</code></a>: Returns the <a href="Method.html"><code>Method</code></a> object for the given singleton method in <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-singleton_methods"><code>singleton_methods</code></a>: Returns an array of the symbol names of the singleton methods in <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-define_singleton_method"><code>define_singleton_method</code></a>: Defines a singleton method in <code>self</code> for the given symbol method-name and block or proc.</p>
</li><li>
<p><a href="Object.html#method-i-extend"><code>extend</code></a>: Includes the given modules in the singleton class of <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-public_send"><code>public_send</code></a>: Calls the given public method in <code>self</code> with the given argument.</p>
</li><li>
<p><a href="Object.html#method-i-send"><code>send</code></a>: Calls the given method in <code>self</code> with the given argument.</p>
</li></ul>

<h3 id="class-Object-label-Instance+Variables">Instance Variables<span><a href="#class-Object-label-Instance+Variables">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="Object.html#method-i-instance_variable_get"><code>instance_variable_get</code></a>: Returns the value of the given instance variable in <code>self</code>, or <code>nil</code> if the instance variable is not set.</p>
</li><li>
<p><a href="Object.html#method-i-instance_variable_set"><code>instance_variable_set</code></a>: Sets the value of the given instance variable in <code>self</code> to the given object.</p>
</li><li>
<p><a href="Object.html#method-i-instance_variables"><code>instance_variables</code></a>: Returns an array of the symbol names of the instance variables in <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-remove_instance_variable"><code>remove_instance_variable</code></a>: Removes the named instance variable from <code>self</code>.</p>
</li></ul>

<h3 id="class-Object-label-Other">Other<span><a href="#class-Object-label-Other">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="Kernel.html#method-i-clone"><code>clone</code></a>:  Returns a shallow copy of <code>self</code>, including singleton class and frozen state.</p>
</li><li>
<p><a href="Object.html#method-i-define_singleton_method"><code>define_singleton_method</code></a>: Defines a singleton method in <code>self</code> for the given symbol method-name and block or proc.</p>
</li><li>
<p><a href="Object.html#method-i-display"><code>display</code></a>: Prints <code>self</code> to the given <a href="IO.html"><code>IO</code></a> stream or <code>$stdout</code>.</p>
</li><li>
<p><a href="Object.html#method-i-dup"><code>dup</code></a>: Returns a shallow unfrozen copy of <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-enum_for"><code>enum_for</code></a> (aliased as <a href="Object.html#method-i-to_enum"><code>to_enum</code></a>): Returns an <a href="Enumerator.html"><code>Enumerator</code></a> for <code>self</code> using the using the given method, arguments, and block.</p>
</li><li>
<p><a href="Object.html#method-i-extend"><code>extend</code></a>: Includes the given modules in the singleton class of <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-freeze"><code>freeze</code></a>: Prevents further modifications to <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-hash"><code>hash</code></a>: Returns the integer hash value for <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-inspect"><code>inspect</code></a>: Returns a human-readable  string representation of <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-itself"><code>itself</code></a>: Returns <code>self</code>.</p>
</li><li>
<p><a href="BasicObject.html#method-i-method_missing"><code>method_missing</code></a>: <a href="Method.html"><code>Method</code></a> called when an undefined method is called on <code>self</code>.</p>
</li><li>
<p><a href="Object.html#method-i-public_send"><code>public_send</code></a>: Calls the given public method in <code>self</code> with the given argument.</p>
</li><li>
<p><a href="Object.html#method-i-send"><code>send</code></a>: Calls the given method in <code>self</code> with the given argument.</p>
</li><li>
<p><a href="Object.html#method-i-to_s"><code>to_s</code></a>: Returns a string representation of <code>self</code>.</p>
</li></ul>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="ARGF">ARGF
          <dd><p><a href="ARGF.html"><code>ARGF</code></a> is a stream designed for use in scripts that process files given as command-line arguments or passed in via <a href="Object.html#STDIN"><code>STDIN</code></a>.</p>

<p>See <a href="ARGF.html"><code>ARGF</code></a> (the class) for more details.</p>
          <dt id="ARGV">ARGV
          <dd><p><a href="Object.html#ARGV"><code>ARGV</code></a> contains the command line arguments used to run ruby.</p>

<p>A library like OptionParser can be used to process command-line arguments.</p>
          <dt id="DATA">DATA
          <dd><p><a href="Object.html#DATA"><code>DATA</code></a> is a <a href="File.html"><code>File</code></a> that contains the data section of the executed file. To create a data section use <code>__END__</code>:</p>

<pre>$ cat t.rb
puts DATA.gets
__END__
hello world!

$ ruby t.rb
hello world!</pre>
          <dt id="ENV">ENV
          <dd><p>ENV is a Hash-like accessor for environment variables.</p>

<p>See <a href="ENV.html"><code>ENV</code></a> (the class) for more details.</p>
          <dt id="RUBY_COPYRIGHT">RUBY_COPYRIGHT
          <dd><p>The copyright string for ruby</p>
          <dt id="RUBY_DESCRIPTION">RUBY_DESCRIPTION
          <dd><p>The full ruby version string, like <code>ruby -v</code> prints</p>
          <dt id="RUBY_ENGINE">RUBY_ENGINE
          <dd><p>The engine or interpreter this ruby uses.</p>
          <dt id="RUBY_ENGINE_VERSION">RUBY_ENGINE_VERSION
          <dd><p>The version of the engine or interpreter this ruby uses.</p>
          <dt id="RUBY_PATCHLEVEL">RUBY_PATCHLEVEL
          <dd><p>The patchlevel for this ruby.  If this is a development build of ruby the patchlevel will be -1</p>
          <dt id="RUBY_PLATFORM">RUBY_PLATFORM
          <dd><p>The platform for this ruby</p>
          <dt id="RUBY_RELEASE_DATE">RUBY_RELEASE_DATE
          <dd><p>The date this ruby was released</p>
          <dt id="RUBY_REVISION">RUBY_REVISION
          <dd><p>The GIT commit hash for this ruby.</p>
          <dt id="RUBY_VERSION">RUBY_VERSION
          <dd><p>The running version of ruby</p>
          <dt id="STDERR">STDERR
          <dd><p>Holds the original stderr</p>
          <dt id="STDIN">STDIN
          <dd><p>Holds the original stdin</p>
          <dt id="STDOUT">STDOUT
          <dd><p>Holds the original stdout</p>
          <dt id="TOPLEVEL_BINDING">TOPLEVEL_BINDING
          <dd><p>The <a href="Binding.html"><code>Binding</code></a> of the top level scope</p>
        </dl>
        </section>



                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-21~" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          obj !~ other  &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns true if two objects do not match (using the <em>=~</em> method), otherwise false.</p>

                              <div class="method-source-code" id="21~-source">
            <pre>static VALUE
rb_obj_not_match(VALUE obj1, VALUE obj2)
{
    VALUE result = rb_funcall(obj1, id_match, 1, obj2);
    return rb_obj_not(result);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-3C-3D-3E" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          obj &lt;=&gt; other &rarr; 0 or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns 0 if <code>obj</code> and <code>other</code> are the same object or <code>obj == other</code>, otherwise nil.</p>

<p>The #&lt;=&gt; is used by various methods to compare objects, for example <a href="Enumerable.html#method-i-sort"><code>Enumerable#sort</code></a>, <a href="Enumerable.html#method-i-max"><code>Enumerable#max</code></a> etc.</p>

<p>Your implementation of #&lt;=&gt; should return one of the following values: -1, 0, 1 or nil. -1 means self is smaller than other. 0 means self is equal to other. 1 means self is bigger than other. Nil means the two values could not be compared.</p>

<p>When you define #&lt;=&gt;, you can include <a href="Comparable.html"><code>Comparable</code></a> to gain the methods #&lt;=, #&lt;, <a href="BasicObject.html#method-i-3D-3D"><code>==</code></a>, #&gt;=, #&gt; and between?.</p>

                              <div class="method-source-code" id="3C-3D-3E-source">
            <pre>static VALUE
rb_obj_cmp(VALUE obj1, VALUE obj2)
{
    if (rb_equal(obj1, obj2))
        return INT2FIX(0);
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-3D-3D-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          true === other &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          false === other &rarr; true or false
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          nil === other &rarr; true or false
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> or <code>false</code>.</p>

<p>Like <a href="BasicObject.html#method-i-3D-3D"><code>Object#==</code></a>, if <code>object</code> is an instance of <a href="Object.html"><code>Object</code></a> (and not an instance of one of its many subclasses).</p>

<p>This method is commonly overridden by those subclasses, to provide meaningful semantics in <code>case</code> statements.</p>

                              <div class="method-source-code" id="3D-3D-3D-source">
            <pre>#define case_equal rb_equal</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-define_singleton_method" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          define_singleton_method(symbol, method) &rarr; symbol
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          define_singleton_method(symbol) { block } &rarr; symbol
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Defines a public singleton method in the receiver. The <em>method</em> parameter can be a <code>Proc</code>, a <code>Method</code> or an <code>UnboundMethod</code> object. If a block is specified, it is used as the method body. If a block or a method has parameters, they’re used as method parameters.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">A</span>
  <span class="ruby-keyword">class</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword">self</span>
    <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">class_name</span>
      <span class="ruby-identifier">to_s</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
<span class="ruby-constant">A</span>.<span class="ruby-identifier">define_singleton_method</span>(<span class="ruby-value">:who_am_i</span>) <span class="ruby-keyword">do</span>
  <span class="ruby-node">&quot;I am: #{class_name}&quot;</span>
<span class="ruby-keyword">end</span>
<span class="ruby-constant">A</span>.<span class="ruby-identifier">who_am_i</span>   <span class="ruby-comment"># ==&gt; &quot;I am: A&quot;</span>

<span class="ruby-identifier">guy</span> = <span class="ruby-string">&quot;Bob&quot;</span>
<span class="ruby-identifier">guy</span>.<span class="ruby-identifier">define_singleton_method</span>(<span class="ruby-value">:hello</span>) { <span class="ruby-node">&quot;#{self}: Hello there!&quot;</span> }
<span class="ruby-identifier">guy</span>.<span class="ruby-identifier">hello</span>    <span class="ruby-comment">#=&gt;  &quot;Bob: Hello there!&quot;</span>

<span class="ruby-identifier">chris</span> = <span class="ruby-string">&quot;Chris&quot;</span>
<span class="ruby-identifier">chris</span>.<span class="ruby-identifier">define_singleton_method</span>(<span class="ruby-value">:greet</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">greeting</span><span class="ruby-operator">|</span> <span class="ruby-node">&quot;#{greeting}, I&#39;m Chris!&quot;</span> }
<span class="ruby-identifier">chris</span>.<span class="ruby-identifier">greet</span>(<span class="ruby-string">&quot;Hi&quot;</span>) <span class="ruby-comment">#=&gt; &quot;Hi, I&#39;m Chris!&quot;</span>
</pre>

                              <div class="method-source-code" id="define_singleton_method-source">
            <pre>static VALUE
rb_obj_define_method(int argc, VALUE *argv, VALUE obj)
{
    VALUE klass = rb_singleton_class(obj);
    const rb_scope_visibility_t scope_visi = {METHOD_VISI_PUBLIC, FALSE};

    return rb_mod_define_method_with_visibility(argc, argv, klass, &amp;scope_visi);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-display" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          display(port = $&gt;) &rarr; nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Writes <code>self</code> on the given port:</p>

<pre class="ruby"><span class="ruby-value">1</span>.<span class="ruby-identifier">display</span>
<span class="ruby-string">&quot;cat&quot;</span>.<span class="ruby-identifier">display</span>
[ <span class="ruby-value">4</span>, <span class="ruby-value">5</span>, <span class="ruby-value">6</span> ].<span class="ruby-identifier">display</span>
<span class="ruby-identifier">puts</span>
</pre>

<p>Output:</p>

<pre>1cat[4, 5, 6]</pre>

                              <div class="method-source-code" id="display-source">
            <pre>static VALUE
rb_obj_display(int argc, VALUE *argv, VALUE self)
{
    VALUE out;

    out = (!rb_check_arity(argc, 0, 1) ? rb_ractor_stdout() : argv[0]);
    rb_io_write(out, self);

    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-dup" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          dup &rarr; an_object
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Produces a shallow copy of <em>obj</em>—the instance variables of <em>obj</em> are copied, but not the objects they reference.</p>

<p>This method may have class-specific behavior.  If so, that behavior will be documented under the #<code>initialize_copy</code> method of the class.</p>

<h3 id="method-i-dup-label-on+dup+vs+clone">on dup vs clone<span><a href="#method-i-dup-label-on+dup+vs+clone">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>In general, <a href="Kernel.html#method-i-clone"><code>clone</code></a> and <a href="Object.html#method-i-dup"><code>dup</code></a> may have different semantics in descendant classes. While <a href="Kernel.html#method-i-clone"><code>clone</code></a> is used to duplicate an object, including its internal state, <a href="Object.html#method-i-dup"><code>dup</code></a> typically uses the class of the descendant object to create the new instance.</p>

<p>When using <a href="Object.html#method-i-dup"><code>dup</code></a>, any modules that the object has been extended with will not be copied.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Klass</span>
  <span class="ruby-identifier">attr_accessor</span> <span class="ruby-value">:str</span>
<span class="ruby-keyword">end</span>

<span class="ruby-keyword">module</span> <span class="ruby-constant">Foo</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">foo</span>; <span class="ruby-string">&#39;foo&#39;</span>; <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">s1</span> = <span class="ruby-constant">Klass</span>.<span class="ruby-identifier">new</span> <span class="ruby-comment">#=&gt; #&lt;Klass:0x401b3a38&gt;</span>
<span class="ruby-identifier">s1</span>.<span class="ruby-identifier">extend</span>(<span class="ruby-constant">Foo</span>) <span class="ruby-comment">#=&gt; #&lt;Klass:0x401b3a38&gt;</span>
<span class="ruby-identifier">s1</span>.<span class="ruby-identifier">foo</span> <span class="ruby-comment">#=&gt; &quot;foo&quot;</span>

<span class="ruby-identifier">s2</span> = <span class="ruby-identifier">s1</span>.<span class="ruby-identifier">clone</span> <span class="ruby-comment">#=&gt; #&lt;Klass:0x401be280&gt;</span>
<span class="ruby-identifier">s2</span>.<span class="ruby-identifier">foo</span> <span class="ruby-comment">#=&gt; &quot;foo&quot;</span>

<span class="ruby-identifier">s3</span> = <span class="ruby-identifier">s1</span>.<span class="ruby-identifier">dup</span> <span class="ruby-comment">#=&gt; #&lt;Klass:0x401c1084&gt;</span>
<span class="ruby-identifier">s3</span>.<span class="ruby-identifier">foo</span> <span class="ruby-comment">#=&gt; NoMethodError: undefined method `foo&#39; for #&lt;Klass:0x401c1084&gt;</span>
</pre>

                              <div class="method-source-code" id="dup-source">
            <pre>VALUE
rb_obj_dup(VALUE obj)
{
    VALUE dup;

    if (special_object_p(obj)) {
        return obj;
    }
    dup = rb_obj_alloc(rb_obj_class(obj));
    init_copy(dup, obj);
    rb_funcall(dup, id_init_dup, 1, obj);

    return dup;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-enum_for" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          enum_for(method = :each, *args)                &rarr; enum
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          enum_for(method = :each, *args){|*args| block} &rarr; enum
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new <a href="Enumerator.html"><code>Enumerator</code></a> which will enumerate by calling <code>method</code> on <code>obj</code>, passing <code>args</code> if any. What was <em>yielded</em> by method becomes values of enumerator.</p>

<p>If a block is given, it will be used to calculate the size of the enumerator without the need to iterate it (see <a href="Enumerator.html#method-i-size"><code>Enumerator#size</code></a>).</p>

<h3 id="method-i-enum_for-label-Examples">Examples<span><a href="#method-i-enum_for-label-Examples">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">str</span> = <span class="ruby-string">&quot;xyz&quot;</span>

<span class="ruby-identifier">enum</span> = <span class="ruby-identifier">str</span>.<span class="ruby-identifier">enum_for</span>(<span class="ruby-value">:each_byte</span>)
<span class="ruby-identifier">enum</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">b</span><span class="ruby-operator">|</span> <span class="ruby-identifier">puts</span> <span class="ruby-identifier">b</span> }
<span class="ruby-comment"># =&gt; 120</span>
<span class="ruby-comment"># =&gt; 121</span>
<span class="ruby-comment"># =&gt; 122</span>

<span class="ruby-comment"># protect an array from being modified by some_method</span>
<span class="ruby-identifier">a</span> = [<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>]
<span class="ruby-identifier">some_method</span>(<span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_enum</span>)

<span class="ruby-comment"># String#split in block form is more memory-effective:</span>
<span class="ruby-identifier">very_large_string</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&quot;|&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">chunk</span><span class="ruby-operator">|</span> <span class="ruby-keyword">return</span> <span class="ruby-identifier">chunk</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">chunk</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-string">&#39;DATE&#39;</span>) }
<span class="ruby-comment"># This could be rewritten more idiomatically with to_enum:</span>
<span class="ruby-identifier">very_large_string</span>.<span class="ruby-identifier">to_enum</span>(<span class="ruby-value">:split</span>, <span class="ruby-string">&quot;|&quot;</span>).<span class="ruby-identifier">lazy</span>.<span class="ruby-identifier">grep</span>(<span class="ruby-regexp">/DATE/</span>).<span class="ruby-identifier">first</span>
</pre>

<p>It is typical to call <a href="Object.html#method-i-to_enum"><code>to_enum</code></a> when defining methods for a generic <a href="Enumerable.html"><code>Enumerable</code></a>, in case no block is passed.</p>

<p>Here is such an example, with parameter passing and a sizing block:</p>

<pre class="ruby"><span class="ruby-keyword">module</span> <span class="ruby-constant">Enumerable</span>
  <span class="ruby-comment"># a generic method to repeat the values of any enumerable</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">repeat</span>(<span class="ruby-identifier">n</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;#{n} is negative!&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">n</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>
      <span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span>(<span class="ruby-identifier">__method__</span>, <span class="ruby-identifier">n</span>) <span class="ruby-keyword">do</span> <span class="ruby-comment"># __method__ is :repeat here</span>
        <span class="ruby-identifier">sz</span> = <span class="ruby-identifier">size</span>     <span class="ruby-comment"># Call size and multiply by n...</span>
        <span class="ruby-identifier">sz</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">n</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">sz</span>  <span class="ruby-comment"># but return nil if size itself is nil</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-operator">*</span><span class="ruby-identifier">val</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">n</span>.<span class="ruby-identifier">times</span> { <span class="ruby-keyword">yield</span> <span class="ruby-operator">*</span><span class="ruby-identifier">val</span> }
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-node">%i[hello world]</span>.<span class="ruby-identifier">repeat</span>(<span class="ruby-value">2</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span> <span class="ruby-identifier">puts</span> <span class="ruby-identifier">w</span> }
  <span class="ruby-comment"># =&gt; Prints &#39;hello&#39;, &#39;hello&#39;, &#39;world&#39;, &#39;world&#39;</span>
<span class="ruby-identifier">enum</span> = (<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">14</span>).<span class="ruby-identifier">repeat</span>(<span class="ruby-value">3</span>)
  <span class="ruby-comment"># =&gt; returns an Enumerator when called without a block</span>
<span class="ruby-identifier">enum</span>.<span class="ruby-identifier">first</span>(<span class="ruby-value">4</span>) <span class="ruby-comment"># =&gt; [1, 1, 1, 2]</span>
<span class="ruby-identifier">enum</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment"># =&gt; 42</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Object.html#method-i-to_enum">to_enum</a>
                            </div>
                          </div>

                  <div id="method-i-eql-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          obj == other        &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          equal?(other)   &rarr; true or false
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          eql?(other)     &rarr; true or false
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Equality — At the <a href="Object.html"><code>Object</code></a> level, <a href="BasicObject.html#method-i-3D-3D"><code>==</code></a> returns <code>true</code> only if <code>obj</code> and <code>other</code> are the same object.  Typically, this method is overridden in descendant classes to provide class-specific meaning.</p>

<p>Unlike <a href="BasicObject.html#method-i-3D-3D"><code>==</code></a>, the <a href="BasicObject.html#method-i-equal-3F"><code>equal?</code></a> method should never be overridden by subclasses as it is used to determine object identity (that is, <code>a.equal?(b)</code> if and only if <code>a</code> is the same object as <code>b</code>):</p>

<pre class="ruby"><span class="ruby-identifier">obj</span> = <span class="ruby-string">&quot;a&quot;</span>
<span class="ruby-identifier">other</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">dup</span>

<span class="ruby-identifier">obj</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other</span>      <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">equal?</span> <span class="ruby-identifier">other</span>  <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">equal?</span> <span class="ruby-identifier">obj</span>    <span class="ruby-comment">#=&gt; true</span>
</pre>

<p>The <a href="Object.html#method-i-eql-3F"><code>eql?</code></a> method returns <code>true</code> if <code>obj</code> and <code>other</code> refer to the same hash key.  This is used by <a href="Hash.html"><code>Hash</code></a> to test members for equality.  For any pair of objects where <a href="Object.html#method-i-eql-3F"><code>eql?</code></a> returns <code>true</code>, the <a href="Object.html#method-i-hash"><code>hash</code></a> value of both objects must be equal. So any subclass that overrides <a href="Object.html#method-i-eql-3F"><code>eql?</code></a> should also override <a href="Object.html#method-i-hash"><code>hash</code></a> appropriately.</p>

<p>For objects of class <a href="Object.html"><code>Object</code></a>, <a href="Object.html#method-i-eql-3F"><code>eql?</code></a>  is synonymous with <a href="BasicObject.html#method-i-3D-3D"><code>==</code></a>.  Subclasses normally continue this tradition by aliasing <a href="Object.html#method-i-eql-3F"><code>eql?</code></a> to their overridden <a href="BasicObject.html#method-i-3D-3D"><code>==</code></a> method, but there are exceptions. <a href="Numeric.html"><code>Numeric</code></a> types, for example, perform type conversion across <a href="BasicObject.html#method-i-3D-3D"><code>==</code></a>, but not across <a href="Object.html#method-i-eql-3F"><code>eql?</code></a>, so:</p>

<pre class="ruby"><span class="ruby-value">1</span> <span class="ruby-operator">==</span> <span class="ruby-value">1.0</span>     <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-value">1</span>.<span class="ruby-identifier">eql?</span> <span class="ruby-value">1.0</span>   <span class="ruby-comment">#=&gt; false</span>
</pre>

                              <div class="method-source-code" id="eql-3F-source">
            <pre>VALUE
rb_obj_equal(VALUE obj1, VALUE obj2)
{
    return RBOOL(obj1 == obj2);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-extend" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          extend(module, ...)    &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Adds to <em>obj</em> the instance methods from each module given as a parameter.</p>

<pre class="ruby"><span class="ruby-keyword">module</span> <span class="ruby-constant">Mod</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hello</span>
    <span class="ruby-string">&quot;Hello from Mod.\n&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-keyword">class</span> <span class="ruby-constant">Klass</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hello</span>
    <span class="ruby-string">&quot;Hello from Klass.\n&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">k</span> = <span class="ruby-constant">Klass</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">k</span>.<span class="ruby-identifier">hello</span>         <span class="ruby-comment">#=&gt; &quot;Hello from Klass.\n&quot;</span>
<span class="ruby-identifier">k</span>.<span class="ruby-identifier">extend</span>(<span class="ruby-constant">Mod</span>)   <span class="ruby-comment">#=&gt; #&lt;Klass:0x401b3bc8&gt;</span>
<span class="ruby-identifier">k</span>.<span class="ruby-identifier">hello</span>         <span class="ruby-comment">#=&gt; &quot;Hello from Mod.\n&quot;</span>
</pre>

                              <div class="method-source-code" id="extend-source">
            <pre>static VALUE
rb_obj_extend(int argc, VALUE *argv, VALUE obj)
{
    int i;
    ID id_extend_object, id_extended;

    CONST_ID(id_extend_object, &quot;extend_object&quot;);
    CONST_ID(id_extended, &quot;extended&quot;);

    rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
    for (i = 0; i &lt; argc; i++) {
        Check_Type(argv[i], T_MODULE);
        if (FL_TEST(argv[i], RMODULE_IS_REFINEMENT)) {
            rb_raise(rb_eTypeError, &quot;Cannot extend object with refinement&quot;);
        }
    }
    while (argc--) {
        rb_funcall(argv[argc], id_extend_object, 1, obj);
        rb_funcall(argv[argc], id_extended, 1, obj);
    }
    return obj;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-freeze" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          freeze    &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Prevents further modifications to <em>obj</em>. A <a href="FrozenError.html"><code>FrozenError</code></a> will be raised if modification is attempted. There is no way to unfreeze a frozen object. See also <a href="Kernel.html#method-i-frozen-3F"><code>Object#frozen?</code></a>.</p>

<p>This method returns self.</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = [ <span class="ruby-string">&quot;a&quot;</span>, <span class="ruby-string">&quot;b&quot;</span>, <span class="ruby-string">&quot;c&quot;</span> ]
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">freeze</span>
<span class="ruby-identifier">a</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;z&quot;</span>
</pre>

<p><em>produces:</em></p>

<pre>prog.rb:3:in `&lt;&lt;&#39;: can&#39;t modify frozen Array (FrozenError)
 from prog.rb:3</pre>

<p>Objects of the following classes are always frozen: <a href="Integer.html"><code>Integer</code></a>, <a href="Float.html"><code>Float</code></a>, <a href="Symbol.html"><code>Symbol</code></a>.</p>

                              <div class="method-source-code" id="freeze-source">
            <pre>VALUE
rb_obj_freeze(VALUE obj)
{
    if (!OBJ_FROZEN(obj)) {
        OBJ_FREEZE(obj);
        if (SPECIAL_CONST_P(obj)) {
            rb_bug(&quot;special consts should be frozen.&quot;);
        }
    }
    return obj;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-hash" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          hash    &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Generates an <a href="Integer.html"><code>Integer</code></a> hash value for this object.  This function must have the property that <code>a.eql?(b)</code> implies <code>a.hash == b.hash</code>.</p>

<p>The hash value is used along with <a href="Object.html#method-i-eql-3F"><code>eql?</code></a> by the <a href="Hash.html"><code>Hash</code></a> class to determine if two objects reference the same hash key.  Any hash value that exceeds the capacity of an <a href="Integer.html"><code>Integer</code></a> will be truncated before being used.</p>

<p>The hash value for an object may not be identical across invocations or implementations of Ruby.  If you need a stable identifier across Ruby invocations and implementations you will need to generate one with a custom method.</p>

<p>Certain core classes such as <a href="Integer.html"><code>Integer</code></a> use built-in hash calculations and do not call the <a href="Object.html#method-i-hash"><code>hash</code></a> method when used as a hash key.</p>

<p>When implementing your own <a href="Object.html#method-i-hash"><code>hash</code></a> based on multiple values, the best practice is to combine the class and any values using the hash code of an array:</p>

<p>For example:</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hash</span>
  [<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">c</span>].<span class="ruby-identifier">hash</span>
<span class="ruby-keyword">end</span>
</pre>

<p>The reason for this is that the <a href="Array.html#method-i-hash"><code>Array#hash</code></a> method already has logic for safely and efficiently combining multiple hash values.</p>

                              <div class="method-source-code" id="hash-source">
            <pre>VALUE
rb_obj_hash(VALUE obj)
{
    long hnum = any_hash(obj, objid_hash);
    return ST2FIX(hnum);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          inspect   &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a string containing a human-readable representation of <em>obj</em>. The default <a href="Object.html#method-i-inspect"><code>inspect</code></a> shows the object’s class name, an encoding of its memory address, and a list of the instance variables and their values (by calling <a href="Object.html#method-i-inspect"><code>inspect</code></a> on each of them).  User defined classes should override this method to provide a better representation of <em>obj</em>.  When overriding this method, it should return a string whose encoding is compatible with the default external encoding.</p>

<pre class="ruby">[ <span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span><span class="ruby-operator">..</span><span class="ruby-value">4</span>, <span class="ruby-string">&#39;five&#39;</span> ].<span class="ruby-identifier">inspect</span>   <span class="ruby-comment">#=&gt; &quot;[1, 2, 3..4, \&quot;five\&quot;]&quot;</span>
<span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">inspect</span>                 <span class="ruby-comment">#=&gt; &quot;2008-03-08 19:43:39 +0900&quot;</span>

<span class="ruby-keyword">class</span> <span class="ruby-constant">Foo</span>
<span class="ruby-keyword">end</span>
<span class="ruby-constant">Foo</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">inspect</span>                  <span class="ruby-comment">#=&gt; &quot;#&lt;Foo:0x0300c868&gt;&quot;</span>

<span class="ruby-keyword">class</span> <span class="ruby-constant">Bar</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>
    <span class="ruby-ivar">@bar</span> = <span class="ruby-value">1</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
<span class="ruby-constant">Bar</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">inspect</span>                  <span class="ruby-comment">#=&gt; &quot;#&lt;Bar:0x0300c868 @bar=1&gt;&quot;</span>
</pre>

                              <div class="method-source-code" id="inspect-source">
            <pre>static VALUE
rb_obj_inspect(VALUE obj)
{
    if (rb_ivar_count(obj) &gt; 0) {
        VALUE str;
        VALUE c = rb_class_name(CLASS_OF(obj));

        str = rb_sprintf(&quot;-&lt;%&quot;PRIsVALUE&quot;:%p&quot;, c, (void*)obj);
        return rb_exec_recursive(inspect_obj, obj, str);
    }
    else {
        return rb_any_to_s(obj);
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-instance_of-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          instance_of?(class)    &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <em>obj</em> is an instance of the given class. See also <a href="Object.html#method-i-kind_of-3F"><code>Object#kind_of?</code></a>.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">A</span>;     <span class="ruby-keyword">end</span>
<span class="ruby-keyword">class</span> <span class="ruby-constant">B</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">A</span>; <span class="ruby-keyword">end</span>
<span class="ruby-keyword">class</span> <span class="ruby-constant">C</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">B</span>; <span class="ruby-keyword">end</span>

<span class="ruby-identifier">b</span> = <span class="ruby-constant">B</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">instance_of?</span> <span class="ruby-constant">A</span>   <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">instance_of?</span> <span class="ruby-constant">B</span>   <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">instance_of?</span> <span class="ruby-constant">C</span>   <span class="ruby-comment">#=&gt; false</span>
</pre>

                              <div class="method-source-code" id="instance_of-3F-source">
            <pre>VALUE
rb_obj_is_instance_of(VALUE obj, VALUE c)
{
    c = class_or_module_required(c);
    return RBOOL(rb_obj_class(obj) == c);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-instance_variable_defined-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          instance_variable_defined?(symbol)    &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          instance_variable_defined?(string)    &rarr; true or false
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the given instance variable is defined in <em>obj</em>. <a href="String.html"><code>String</code></a> arguments are converted to symbols.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Fred</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">p1</span>, <span class="ruby-identifier">p2</span>)
    <span class="ruby-ivar">@a</span>, <span class="ruby-ivar">@b</span> = <span class="ruby-identifier">p1</span>, <span class="ruby-identifier">p2</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">fred</span> = <span class="ruby-constant">Fred</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;cat&#39;</span>, <span class="ruby-value">99</span>)
<span class="ruby-identifier">fred</span>.<span class="ruby-identifier">instance_variable_defined?</span>(<span class="ruby-value">:@a</span>)    <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">fred</span>.<span class="ruby-identifier">instance_variable_defined?</span>(<span class="ruby-string">&quot;@b&quot;</span>)   <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">fred</span>.<span class="ruby-identifier">instance_variable_defined?</span>(<span class="ruby-string">&quot;@c&quot;</span>)   <span class="ruby-comment">#=&gt; false</span>
</pre>

                              <div class="method-source-code" id="instance_variable_defined-3F-source">
            <pre>static VALUE
rb_obj_ivar_defined(VALUE obj, VALUE iv)
{
    ID id = id_for_var(obj, iv, instance);

    if (!id) {
        return Qfalse;
    }
    return rb_ivar_defined(obj, id);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-instance_variable_get" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          instance_variable_get(symbol)    &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          instance_variable_get(string)    &rarr; obj
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns the value of the given instance variable, or nil if the instance variable is not set. The <code>@</code> part of the variable name should be included for regular instance variables. Throws a <a href="NameError.html"><code>NameError</code></a> exception if the supplied symbol is not valid as an instance variable name. <a href="String.html"><code>String</code></a> arguments are converted to symbols.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Fred</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">p1</span>, <span class="ruby-identifier">p2</span>)
    <span class="ruby-ivar">@a</span>, <span class="ruby-ivar">@b</span> = <span class="ruby-identifier">p1</span>, <span class="ruby-identifier">p2</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">fred</span> = <span class="ruby-constant">Fred</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;cat&#39;</span>, <span class="ruby-value">99</span>)
<span class="ruby-identifier">fred</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-value">:@a</span>)    <span class="ruby-comment">#=&gt; &quot;cat&quot;</span>
<span class="ruby-identifier">fred</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-string">&quot;@b&quot;</span>)   <span class="ruby-comment">#=&gt; 99</span>
</pre>

                              <div class="method-source-code" id="instance_variable_get-source">
            <pre>static VALUE
rb_obj_ivar_get(VALUE obj, VALUE iv)
{
    ID id = id_for_var(obj, iv, instance);

    if (!id) {
        return Qnil;
    }
    return rb_ivar_get(obj, id);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-instance_variable_set" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          instance_variable_set(symbol, obj)    &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          instance_variable_set(string, obj)    &rarr; obj
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Sets the instance variable named by <em>symbol</em> to the given object. This may circumvent the encapsulation intended by the author of the class, so it should be used with care. The variable does not have to exist prior to this call. If the instance variable name is passed as a string, that string is converted to a symbol.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Fred</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">p1</span>, <span class="ruby-identifier">p2</span>)
    <span class="ruby-ivar">@a</span>, <span class="ruby-ivar">@b</span> = <span class="ruby-identifier">p1</span>, <span class="ruby-identifier">p2</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">fred</span> = <span class="ruby-constant">Fred</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;cat&#39;</span>, <span class="ruby-value">99</span>)
<span class="ruby-identifier">fred</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value">:@a</span>, <span class="ruby-string">&#39;dog&#39;</span>)   <span class="ruby-comment">#=&gt; &quot;dog&quot;</span>
<span class="ruby-identifier">fred</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value">:@c</span>, <span class="ruby-string">&#39;cat&#39;</span>)   <span class="ruby-comment">#=&gt; &quot;cat&quot;</span>
<span class="ruby-identifier">fred</span>.<span class="ruby-identifier">inspect</span>                             <span class="ruby-comment">#=&gt; &quot;#&lt;Fred:0x401b3da8 @a=\&quot;dog\&quot;, @b=99, @c=\&quot;cat\&quot;&gt;&quot;</span>
</pre>

                              <div class="method-source-code" id="instance_variable_set-source">
            <pre>static VALUE
rb_obj_ivar_set_m(VALUE obj, VALUE iv, VALUE val)
{
    ID id = id_for_var(obj, iv, instance);
    if (!id) id = rb_intern_str(iv);
    return rb_ivar_set(obj, id, val);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-instance_variables" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          instance_variables    &rarr; array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array of instance variable names for the receiver. Note that simply defining an accessor does not create the corresponding instance variable.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Fred</span>
  <span class="ruby-identifier">attr_accessor</span> <span class="ruby-value">:a1</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>
    <span class="ruby-ivar">@iv</span> = <span class="ruby-value">3</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
<span class="ruby-constant">Fred</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">instance_variables</span>   <span class="ruby-comment">#=&gt; [:@iv]</span>
</pre>

                              <div class="method-source-code" id="instance_variables-source">
            <pre>VALUE
rb_obj_instance_variables(VALUE obj)
{
    VALUE ary;

    ary = rb_ary_new();
    rb_ivar_foreach(obj, ivar_i, ary);
    return ary;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-is_a-3F" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          is_a?(class)       &rarr; true or false
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <em>class</em> is the class of <em>obj</em>, or if <em>class</em> is one of the superclasses of <em>obj</em> or modules included in <em>obj</em>.</p>

<pre class="ruby"><span class="ruby-keyword">module</span> <span class="ruby-constant">M</span>;    <span class="ruby-keyword">end</span>
<span class="ruby-keyword">class</span> <span class="ruby-constant">A</span>
  <span class="ruby-identifier">include</span> <span class="ruby-constant">M</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">class</span> <span class="ruby-constant">B</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">A</span>; <span class="ruby-keyword">end</span>
<span class="ruby-keyword">class</span> <span class="ruby-constant">C</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">B</span>; <span class="ruby-keyword">end</span>

<span class="ruby-identifier">b</span> = <span class="ruby-constant">B</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">A</span>          <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">B</span>          <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">C</span>          <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">M</span>          <span class="ruby-comment">#=&gt; true</span>

<span class="ruby-identifier">b</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">A</span>       <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">B</span>       <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">C</span>       <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">M</span>       <span class="ruby-comment">#=&gt; true</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Object.html#method-i-kind_of-3F">kind_of?</a>
                            </div>
                          </div>

                  <div id="method-i-itself" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          itself    &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the receiver.</p>

<pre class="ruby"><span class="ruby-identifier">string</span> = <span class="ruby-string">&quot;my string&quot;</span>
<span class="ruby-identifier">string</span>.<span class="ruby-identifier">itself</span>.<span class="ruby-identifier">object_id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">string</span>.<span class="ruby-identifier">object_id</span>   <span class="ruby-comment">#=&gt; true</span>
</pre>

                              <div class="method-source-code" id="itself-source">
            <pre>static VALUE
rb_obj_itself(VALUE obj)
{
    return obj;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-kind_of-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          kind_of?(class)    &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <em>class</em> is the class of <em>obj</em>, or if <em>class</em> is one of the superclasses of <em>obj</em> or modules included in <em>obj</em>.</p>

<pre class="ruby"><span class="ruby-keyword">module</span> <span class="ruby-constant">M</span>;    <span class="ruby-keyword">end</span>
<span class="ruby-keyword">class</span> <span class="ruby-constant">A</span>
  <span class="ruby-identifier">include</span> <span class="ruby-constant">M</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">class</span> <span class="ruby-constant">B</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">A</span>; <span class="ruby-keyword">end</span>
<span class="ruby-keyword">class</span> <span class="ruby-constant">C</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">B</span>; <span class="ruby-keyword">end</span>

<span class="ruby-identifier">b</span> = <span class="ruby-constant">B</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">A</span>          <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">B</span>          <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">C</span>          <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">M</span>          <span class="ruby-comment">#=&gt; true</span>

<span class="ruby-identifier">b</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">A</span>       <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">B</span>       <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">C</span>       <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">M</span>       <span class="ruby-comment">#=&gt; true</span>
</pre>

                              <div class="method-source-code" id="kind_of-3F-source">
            <pre>VALUE
rb_obj_is_kind_of(VALUE obj, VALUE c)
{
    VALUE cl = CLASS_OF(obj);

    RUBY_ASSERT(RB_TYPE_P(cl, T_CLASS));

    // Fastest path: If the object&#39;s class is an exact match we know `c` is a
    // class without checking type and can return immediately.
    if (cl == c) return Qtrue;

    // Note: YJIT needs this function to never allocate and never raise when
    // `c` is a class or a module.

    if (LIKELY(RB_TYPE_P(c, T_CLASS))) {
        // Fast path: Both are T_CLASS
        return class_search_class_ancestor(cl, c);
    }
    else if (RB_TYPE_P(c, T_ICLASS)) {
        // First check if we inherit the includer
        // If we do we can return true immediately
        VALUE includer = RCLASS_INCLUDER(c);
        if (cl == includer) return Qtrue;

        // Usually includer is a T_CLASS here, except when including into an
        // already included Module.
        // If it is a class, attempt the fast class-to-class check and return
        // true if there is a match.
        if (RB_TYPE_P(includer, T_CLASS) &amp;&amp; class_search_class_ancestor(cl, includer))
            return Qtrue;

        // We don&#39;t include the ICLASS directly, so must check if we inherit
        // the module via another include
        return RBOOL(class_search_ancestor(cl, RCLASS_ORIGIN(c)));
    }
    else if (RB_TYPE_P(c, T_MODULE)) {
        // Slow path: check each ancestor in the linked list and its method table
        return RBOOL(class_search_ancestor(cl, RCLASS_ORIGIN(c)));
    }
    else {
        rb_raise(rb_eTypeError, &quot;class or module required&quot;);
        UNREACHABLE_RETURN(Qfalse);
    }
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Object.html#method-i-is_a-3F">is_a?</a>
                            </div>

                          </div>

                  <div id="method-i-method" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          method(sym)    &rarr; method
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Looks up the named method as a receiver in <em>obj</em>, returning a <a href="Method.html"><code>Method</code></a> object (or raising <a href="NameError.html"><code>NameError</code></a>). The <a href="Method.html"><code>Method</code></a> object acts as a closure in <em>obj</em>’s object instance, so instance variables and the value of <code>self</code> remain available.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Demo</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">n</span>)
    <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">n</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hello</span>()
    <span class="ruby-node">&quot;Hello, @iv = #{@iv}&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">k</span> = <span class="ruby-constant">Demo</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">99</span>)
<span class="ruby-identifier">m</span> = <span class="ruby-identifier">k</span>.<span class="ruby-identifier">method</span>(<span class="ruby-value">:hello</span>)
<span class="ruby-identifier">m</span>.<span class="ruby-identifier">call</span>   <span class="ruby-comment">#=&gt; &quot;Hello, @iv = 99&quot;</span>

<span class="ruby-identifier">l</span> = <span class="ruby-constant">Demo</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;Fred&#39;</span>)
<span class="ruby-identifier">m</span> = <span class="ruby-identifier">l</span>.<span class="ruby-identifier">method</span>(<span class="ruby-string">&quot;hello&quot;</span>)
<span class="ruby-identifier">m</span>.<span class="ruby-identifier">call</span>   <span class="ruby-comment">#=&gt; &quot;Hello, @iv = Fred&quot;</span>
</pre>

<p>Note that <a href="Method.html"><code>Method</code></a> implements <code>to_proc</code> method, which means it can be used with iterators.</p>

<pre class="ruby">[ <span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span> ].<span class="ruby-identifier">each</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">method</span>(<span class="ruby-value">:puts</span>)) <span class="ruby-comment"># =&gt; prints 3 lines to stdout</span>

<span class="ruby-identifier">out</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&#39;test.txt&#39;</span>, <span class="ruby-string">&#39;w&#39;</span>)
[ <span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span> ].<span class="ruby-identifier">each</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">out</span>.<span class="ruby-identifier">method</span>(<span class="ruby-value">:puts</span>)) <span class="ruby-comment"># =&gt; prints 3 lines to file</span>

<span class="ruby-identifier">require</span> <span class="ruby-string">&#39;date&#39;</span>
<span class="ruby-node">%w[2017-03-01 2017-03-02]</span>.<span class="ruby-identifier">collect</span>(<span class="ruby-operator">&amp;</span><span class="ruby-constant">Date</span>.<span class="ruby-identifier">method</span>(<span class="ruby-value">:parse</span>))
<span class="ruby-comment">#=&gt; [#&lt;Date: 2017-03-01 ((2457814j,0s,0n),+0s,2299161j)&gt;, #&lt;Date: 2017-03-02 ((2457815j,0s,0n),+0s,2299161j)&gt;]</span>
</pre>

                              <div class="method-source-code" id="method-source">
            <pre>VALUE
rb_obj_method(VALUE obj, VALUE vid)
{
    return obj_method(obj, vid, FALSE);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-methods" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          methods(regular=true)    &rarr; array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a list of the names of public and protected methods of <em>obj</em>. This will include all the methods accessible in <em>obj</em>’s ancestors. If the optional parameter is <code>false</code>, it returns an array of <em>obj</em>’s public and protected singleton methods, the array will not include methods in modules included in <em>obj</em>.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Klass</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">klass_method</span>()
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">k</span> = <span class="ruby-constant">Klass</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">k</span>.<span class="ruby-identifier">methods</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">9</span>]    <span class="ruby-comment">#=&gt; [:klass_method, :nil?, :===,</span>
                   <span class="ruby-comment">#    :==~, :!, :eql?</span>
                   <span class="ruby-comment">#    :hash, :&lt;=&gt;, :class, :singleton_class]</span>
<span class="ruby-identifier">k</span>.<span class="ruby-identifier">methods</span>.<span class="ruby-identifier">length</span>   <span class="ruby-comment">#=&gt; 56</span>

<span class="ruby-identifier">k</span>.<span class="ruby-identifier">methods</span>(<span class="ruby-keyword">false</span>)   <span class="ruby-comment">#=&gt; []</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">k</span>.<span class="ruby-identifier">singleton_method</span>; <span class="ruby-keyword">end</span>
<span class="ruby-identifier">k</span>.<span class="ruby-identifier">methods</span>(<span class="ruby-keyword">false</span>)   <span class="ruby-comment">#=&gt; [:singleton_method]</span>

<span class="ruby-keyword">module</span> <span class="ruby-constant">M123</span>; <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">m123</span>; <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span>
<span class="ruby-identifier">k</span>.<span class="ruby-identifier">extend</span> <span class="ruby-constant">M123</span>
<span class="ruby-identifier">k</span>.<span class="ruby-identifier">methods</span>(<span class="ruby-keyword">false</span>)   <span class="ruby-comment">#=&gt; [:singleton_method]</span>
</pre>

                              <div class="method-source-code" id="methods-source">
            <pre>VALUE
rb_obj_methods(int argc, const VALUE *argv, VALUE obj)
{
    rb_check_arity(argc, 0, 1);
    if (argc &gt; 0 &amp;&amp; !RTEST(argv[0])) {
        return rb_obj_singleton_methods(argc, argv, obj);
    }
    return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_i);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-nil-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          nil?               &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Only the object <em>nil</em> responds <code>true</code> to <code>nil?</code>.</p>

<pre class="ruby"><span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">nil?</span>   <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-keyword">nil</span>.<span class="ruby-identifier">nil?</span>          <span class="ruby-comment">#=&gt; true</span>
</pre>

                              <div class="method-source-code" id="nil-3F-source">
            <pre>VALUE
rb_false(VALUE obj)
{
    return Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-object_id" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          __id__       &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          object_id    &rarr; integer
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns an integer identifier for <code>obj</code>.</p>

<p>The same number will be returned on all calls to <code>object_id</code> for a given object, and no two active objects will share an id.</p>

<p>Note: that some objects of builtin classes are reused for optimization. This is the case for immediate values and frozen string literals.</p>

<p><a href="BasicObject.html"><code>BasicObject</code></a> implements +__id__+, <a href="Kernel.html"><code>Kernel</code></a> implements <code>object_id</code>.</p>

<p>Immediate values are not passed by reference but are passed by value: <code>nil</code>, <code>true</code>, <code>false</code>, Fixnums, Symbols, and some Floats.</p>

<pre class="ruby"><span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">object_id</span>  <span class="ruby-operator">==</span> <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">object_id</span>  <span class="ruby-comment"># =&gt; false</span>
(<span class="ruby-value">21</span> <span class="ruby-operator">*</span> <span class="ruby-value">2</span>).<span class="ruby-identifier">object_id</span>    <span class="ruby-operator">==</span> (<span class="ruby-value">21</span> <span class="ruby-operator">*</span> <span class="ruby-value">2</span>).<span class="ruby-identifier">object_id</span>    <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">object_id</span>     <span class="ruby-operator">==</span> <span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">object_id</span>     <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-string">&quot;hi&quot;</span>.<span class="ruby-identifier">freeze</span>.<span class="ruby-identifier">object_id</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;hi&quot;</span>.<span class="ruby-identifier">freeze</span>.<span class="ruby-identifier">object_id</span> <span class="ruby-comment"># =&gt; true</span>
</pre>

                              <div class="method-source-code" id="object_id-source">
            <pre>VALUE
rb_obj_id(VALUE obj)
{
    /*
     *                32-bit VALUE space
     *          MSB ------------------------ LSB
     *  false   00000000000000000000000000000000
     *  true    00000000000000000000000000000010
     *  nil     00000000000000000000000000000100
     *  undef   00000000000000000000000000000110
     *  symbol  ssssssssssssssssssssssss00001110
     *  object  oooooooooooooooooooooooooooooo00        = 0 (mod sizeof(RVALUE))
     *  fixnum  fffffffffffffffffffffffffffffff1
     *
     *                    object_id space
     *                                       LSB
     *  false   00000000000000000000000000000000
     *  true    00000000000000000000000000000010
     *  nil     00000000000000000000000000000100
     *  undef   00000000000000000000000000000110
     *  symbol   000SSSSSSSSSSSSSSSSSSSSSSSSSSS0        S...S % A = 4 (S...S = s...s * A + 4)
     *  object   oooooooooooooooooooooooooooooo0        o...o % A = 0
     *  fixnum  fffffffffffffffffffffffffffffff1        bignum if required
     *
     *  where A = sizeof(RVALUE)/4
     *
     *  sizeof(RVALUE) is
     *  20 if 32-bit, double is 4-byte aligned
     *  24 if 32-bit, double is 8-byte aligned
     *  40 if 64-bit
     */

    return rb_find_object_id(obj, cached_object_id);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-private_methods" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          private_methods(all=true)   &rarr; array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the list of private methods accessible to <em>obj</em>. If the <em>all</em> parameter is set to <code>false</code>, only those methods in the receiver will be listed.</p>

                              <div class="method-source-code" id="private_methods-source">
            <pre>VALUE
rb_obj_private_methods(int argc, const VALUE *argv, VALUE obj)
{
    return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_priv_i);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-protected_methods" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          protected_methods(all=true)   &rarr; array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the list of protected methods accessible to <em>obj</em>. If the <em>all</em> parameter is set to <code>false</code>, only those methods in the receiver will be listed.</p>

                              <div class="method-source-code" id="protected_methods-source">
            <pre>VALUE
rb_obj_protected_methods(int argc, const VALUE *argv, VALUE obj)
{
    return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_prot_i);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-public_method" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          public_method(sym)    &rarr; method
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Similar to <em>method</em>, searches public method only.</p>

                              <div class="method-source-code" id="public_method-source">
            <pre>VALUE
rb_obj_public_method(VALUE obj, VALUE vid)
{
    return obj_method(obj, vid, TRUE);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-public_methods" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          public_methods(all=true)   &rarr; array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the list of public methods accessible to <em>obj</em>. If the <em>all</em> parameter is set to <code>false</code>, only those methods in the receiver will be listed.</p>

                              <div class="method-source-code" id="public_methods-source">
            <pre>VALUE
rb_obj_public_methods(int argc, const VALUE *argv, VALUE obj)
{
    return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_pub_i);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-public_send" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          public_send(symbol [, args...])  &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          public_send(string [, args...])  &rarr; obj
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Invokes the method identified by <em>symbol</em>, passing it any arguments specified. Unlike send, <a href="Object.html#method-i-public_send"><code>public_send</code></a> calls public methods only. When the method is identified by a string, the string is converted to a symbol.</p>

<pre class="ruby"><span class="ruby-value">1</span>.<span class="ruby-identifier">public_send</span>(<span class="ruby-value">:puts</span>, <span class="ruby-string">&quot;hello&quot;</span>)  <span class="ruby-comment"># causes NoMethodError</span>
</pre>

                              <div class="method-source-code" id="public_send-source">
            <pre>static VALUE
rb_f_public_send(int argc, VALUE *argv, VALUE recv)
{
    return send_internal_kw(argc, argv, recv, CALL_PUBLIC);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-remove_instance_variable" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          remove_instance_variable(symbol)    &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          remove_instance_variable(string)    &rarr; obj
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Removes the named instance variable from <em>obj</em>, returning that variable’s value. <a href="String.html"><code>String</code></a> arguments are converted to symbols.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Dummy</span>
  <span class="ruby-identifier">attr_reader</span> <span class="ruby-value">:var</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>
    <span class="ruby-ivar">@var</span> = <span class="ruby-value">99</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">remove</span>
    <span class="ruby-identifier">remove_instance_variable</span>(<span class="ruby-value">:@var</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">Dummy</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">var</span>      <span class="ruby-comment">#=&gt; 99</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">remove</span>   <span class="ruby-comment">#=&gt; 99</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">var</span>      <span class="ruby-comment">#=&gt; nil</span>
</pre>

                              <div class="method-source-code" id="remove_instance_variable-source">
            <pre>VALUE
rb_obj_remove_instance_variable(VALUE obj, VALUE name)
{
    VALUE val = Qundef;
    const ID id = id_for_var(obj, name, an, instance);

    // Frozen check comes here because it&#39;s expected that we raise a
    // NameError (from the id_for_var check) before we raise a FrozenError
    rb_check_frozen(obj);

    if (!id) {
        goto not_defined;
    }

    rb_shape_t * shape = rb_shape_get_shape(obj);

    switch (BUILTIN_TYPE(obj)) {
      case T_CLASS:
      case T_MODULE:
        IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(id);
        rb_shape_transition_shape_remove_ivar(obj, id, shape, &amp;val);
        break;
      case T_OBJECT: {
        if (rb_shape_obj_too_complex(obj)) {
            if (rb_st_lookup(ROBJECT_IV_HASH(obj), (st_data_t)id, (st_data_t *)&amp;val)) {
                rb_st_delete(ROBJECT_IV_HASH(obj), (st_data_t *)&amp;id, 0);
            }
        }
        else {
            rb_shape_transition_shape_remove_ivar(obj, id, shape, &amp;val);
        }
        break;
      }
      default: {
        rb_shape_transition_shape_remove_ivar(obj, id, shape, &amp;val);
        break;
      }
    }

    if (val != Qundef) {
        return val;
    }

  not_defined:
    rb_name_err_raise(&quot;instance variable %1$s not defined&quot;,
                      obj, name);
    UNREACHABLE_RETURN(Qnil);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-respond_to-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          respond_to?(symbol, include_all=false) &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          respond_to?(string, include_all=false) &rarr; true or false
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <em>obj</em> responds to the given method.  Private and protected methods are included in the search only if the optional second parameter evaluates to <code>true</code>.</p>

<p>If the method is not implemented, as <a href="Process.html#method-c-fork"><code>Process.fork</code></a> on Windows, <a href="File.html#method-c-lchmod"><code>File.lchmod</code></a> on GNU/Linux, etc., false is returned.</p>

<p>If the method is not defined, <code>respond_to_missing?</code> method is called and the result is returned.</p>

<p>When the method name parameter is given as a string, the string is converted to a symbol.</p>

                              <div class="method-source-code" id="respond_to-3F-source">
            <pre>static VALUE
obj_respond_to(int argc, VALUE *argv, VALUE obj)
{
    VALUE mid, priv;
    ID id;
    rb_execution_context_t *ec = GET_EC();

    rb_scan_args(argc, argv, &quot;11&quot;, &amp;mid, &amp;priv);
    if (!(id = rb_check_id(&amp;mid))) {
        VALUE ret = basic_obj_respond_to_missing(ec, CLASS_OF(obj), obj,
                                                 rb_to_symbol(mid), priv);
        if (UNDEF_P(ret)) ret = Qfalse;
        return ret;
    }
    return  RBOOL(basic_obj_respond_to(ec, obj, id, !RTEST(priv)));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-respond_to_missing-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          respond_to_missing?(symbol, include_all) &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          respond_to_missing?(string, include_all) &rarr; true or false
                              </span>
                            </div>

                            <div class="method-description">
                              <p>DO NOT USE THIS DIRECTLY.</p>

<p>Hook method to return whether the <em>obj</em> can respond to <em>id</em> method or not.</p>

<p>When the method name parameter is given as a string, the string is converted to a symbol.</p>

<p>See <a href="Object.html#method-i-respond_to-3F"><code>respond_to?</code></a>, and the example of <a href="BasicObject.html"><code>BasicObject</code></a>.</p>

                              <div class="method-source-code" id="respond_to_missing-3F-source">
            <pre>static VALUE
obj_respond_to_missing(VALUE obj, VALUE mid, VALUE priv)
{
    return Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-send" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          send(symbol [, args...])       &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          __send__(symbol [, args...])   &rarr; obj
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          send(string [, args...])       &rarr; obj
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          __send__(string [, args...])   &rarr; obj
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Invokes the method identified by <em>symbol</em>, passing it any arguments specified. When the method is identified by a string, the string is converted to a symbol.</p>

<p><a href="BasicObject.html"><code>BasicObject</code></a> implements +__send__+, <a href="Kernel.html"><code>Kernel</code></a> implements <code>send</code>. <code>__send__</code> is safer than <code>send</code> when <em>obj</em> has the same method name like <code>Socket</code>. See also <code>public_send</code>.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Klass</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hello</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
    <span class="ruby-string">&quot;Hello &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">&#39; &#39;</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">k</span> = <span class="ruby-constant">Klass</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">k</span>.<span class="ruby-identifier">send</span> <span class="ruby-value">:hello</span>, <span class="ruby-string">&quot;gentle&quot;</span>, <span class="ruby-string">&quot;readers&quot;</span>   <span class="ruby-comment">#=&gt; &quot;Hello gentle readers&quot;</span>
</pre>

                              <div class="method-source-code" id="send-source">
            <pre>VALUE
rb_f_send(int argc, VALUE *argv, VALUE recv)
{
    return send_internal_kw(argc, argv, recv, CALL_FCALL);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-singleton_class" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          singleton_class    &rarr; class
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the singleton class of <em>obj</em>.  This method creates a new singleton class if <em>obj</em> does not have one.</p>

<p>If <em>obj</em> is <code>nil</code>, <code>true</code>, or <code>false</code>, it returns <a href="NilClass.html"><code>NilClass</code></a>, <a href="TrueClass.html"><code>TrueClass</code></a>, or <a href="FalseClass.html"><code>FalseClass</code></a>, respectively. If <em>obj</em> is an <a href="Integer.html"><code>Integer</code></a>, a <a href="Float.html"><code>Float</code></a> or a <a href="Symbol.html"><code>Symbol</code></a>, it raises a <a href="TypeError.html"><code>TypeError</code></a>.</p>

<pre class="ruby"><span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">singleton_class</span>  <span class="ruby-comment">#=&gt; #&lt;Class:#&lt;Object:0xb7ce1e24&gt;&gt;</span>
<span class="ruby-constant">String</span>.<span class="ruby-identifier">singleton_class</span>      <span class="ruby-comment">#=&gt; #&lt;Class:String&gt;</span>
<span class="ruby-keyword">nil</span>.<span class="ruby-identifier">singleton_class</span>         <span class="ruby-comment">#=&gt; NilClass</span>
</pre>

                              <div class="method-source-code" id="singleton_class-source">
            <pre>static VALUE
rb_obj_singleton_class(VALUE obj)
{
    return rb_singleton_class(obj);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-singleton_method" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          singleton_method(sym)    &rarr; method
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Similar to <em>method</em>, searches singleton method only.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Demo</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">n</span>)
    <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">n</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hello</span>()
    <span class="ruby-node">&quot;Hello, @iv = #{@iv}&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">k</span> = <span class="ruby-constant">Demo</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">99</span>)
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">k</span>.<span class="ruby-identifier">hi</span>
  <span class="ruby-node">&quot;Hi, @iv = #{@iv}&quot;</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">m</span> = <span class="ruby-identifier">k</span>.<span class="ruby-identifier">singleton_method</span>(<span class="ruby-value">:hi</span>)
<span class="ruby-identifier">m</span>.<span class="ruby-identifier">call</span>   <span class="ruby-comment">#=&gt; &quot;Hi, @iv = 99&quot;</span>
<span class="ruby-identifier">m</span> = <span class="ruby-identifier">k</span>.<span class="ruby-identifier">singleton_method</span>(<span class="ruby-value">:hello</span>) <span class="ruby-comment">#=&gt; NameError</span>
</pre>

                              <div class="method-source-code" id="singleton_method-source">
            <pre>VALUE
rb_obj_singleton_method(VALUE obj, VALUE vid)
{
    VALUE klass = rb_singleton_class_get(obj);
    ID id = rb_check_id(&amp;vid);

    if (NIL_P(klass) ||
        NIL_P(klass = RCLASS_ORIGIN(klass)) ||
        !NIL_P(rb_special_singleton_class(obj))) {
        /* goto undef; */
    }
    else if (! id) {
        VALUE m = mnew_missing_by_name(klass, obj, &amp;vid, FALSE, rb_cMethod);
        if (m) return m;
        /* else goto undef; */
    }
    else {
        const rb_method_entry_t *me = rb_method_entry_at(klass, id);
        vid = ID2SYM(id);

        if (UNDEFINED_METHOD_ENTRY_P(me)) {
            /* goto undef; */
        }
        else if (UNDEFINED_REFINED_METHOD_P(me-&gt;def)) {
            /* goto undef; */
        }
        else {
            return mnew_from_me(me, klass, klass, obj, id, rb_cMethod, FALSE);
        }
    }

  /* undef: */
    rb_name_err_raise(&quot;undefined singleton method `%1$s&#39; for `%2$s&#39;&quot;,
                      obj, vid);
    UNREACHABLE_RETURN(Qundef);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-singleton_methods" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          singleton_methods(all=true)    &rarr; array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array of the names of singleton methods for <em>obj</em>. If the optional <em>all</em> parameter is true, the list will include methods in modules included in <em>obj</em>. Only public and protected singleton methods are returned.</p>

<pre class="ruby"><span class="ruby-keyword">module</span> <span class="ruby-constant">Other</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">three</span>() <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-keyword">class</span> <span class="ruby-constant">Single</span>
  <span class="ruby-keyword">def</span> <span class="ruby-constant">Single</span>.<span class="ruby-identifier ruby-title">four</span>() <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">a</span> = <span class="ruby-constant">Single</span>.<span class="ruby-identifier">new</span>

<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">a</span>.<span class="ruby-identifier">one</span>()
<span class="ruby-keyword">end</span>

<span class="ruby-keyword">class</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">a</span>
  <span class="ruby-identifier">include</span> <span class="ruby-constant">Other</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">two</span>()
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-constant">Single</span>.<span class="ruby-identifier">singleton_methods</span>    <span class="ruby-comment">#=&gt; [:four]</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">singleton_methods</span>(<span class="ruby-keyword">false</span>)  <span class="ruby-comment">#=&gt; [:two, :one]</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">singleton_methods</span>         <span class="ruby-comment">#=&gt; [:two, :one, :three]</span>
</pre>

                              <div class="method-source-code" id="singleton_methods-source">
            <pre>VALUE
rb_obj_singleton_methods(int argc, const VALUE *argv, VALUE obj)
{
    VALUE ary, klass, origin;
    struct method_entry_arg me_arg;
    struct rb_id_table *mtbl;
    int recur = TRUE;

    if (rb_check_arity(argc, 0, 1)) recur = RTEST(argv[0]);
    if (RB_TYPE_P(obj, T_CLASS) &amp;&amp; FL_TEST(obj, FL_SINGLETON)) {
        rb_singleton_class(obj);
    }
    klass = CLASS_OF(obj);
    origin = RCLASS_ORIGIN(klass);
    me_arg.list = st_init_numtable();
    me_arg.recur = recur;
    if (klass &amp;&amp; FL_TEST(klass, FL_SINGLETON)) {
        if ((mtbl = RCLASS_M_TBL(origin)) != 0) rb_id_table_foreach(mtbl, method_entry_i, &amp;me_arg);
        klass = RCLASS_SUPER(klass);
    }
    if (recur) {
        while (klass &amp;&amp; (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) {
            if (klass != origin &amp;&amp; (mtbl = RCLASS_M_TBL(klass)) != 0) rb_id_table_foreach(mtbl, method_entry_i, &amp;me_arg);
            klass = RCLASS_SUPER(klass);
        }
    }
    ary = rb_ary_new2(me_arg.list-&gt;num_entries);
    st_foreach(me_arg.list, ins_methods_i, ary);
    st_free_table(me_arg.list);

    return ary;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_enum" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_enum(method = :each, *args)                 &rarr; enum
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_enum(method = :each, *args) {|*args| block} &rarr; enum
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new <a href="Enumerator.html"><code>Enumerator</code></a> which will enumerate by calling <code>method</code> on <code>obj</code>, passing <code>args</code> if any. What was <em>yielded</em> by method becomes values of enumerator.</p>

<p>If a block is given, it will be used to calculate the size of the enumerator without the need to iterate it (see <a href="Enumerator.html#method-i-size"><code>Enumerator#size</code></a>).</p>

<h3 id="method-i-to_enum-label-Examples">Examples<span><a href="#method-i-to_enum-label-Examples">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">str</span> = <span class="ruby-string">&quot;xyz&quot;</span>

<span class="ruby-identifier">enum</span> = <span class="ruby-identifier">str</span>.<span class="ruby-identifier">enum_for</span>(<span class="ruby-value">:each_byte</span>)
<span class="ruby-identifier">enum</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">b</span><span class="ruby-operator">|</span> <span class="ruby-identifier">puts</span> <span class="ruby-identifier">b</span> }
<span class="ruby-comment"># =&gt; 120</span>
<span class="ruby-comment"># =&gt; 121</span>
<span class="ruby-comment"># =&gt; 122</span>

<span class="ruby-comment"># protect an array from being modified by some_method</span>
<span class="ruby-identifier">a</span> = [<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>]
<span class="ruby-identifier">some_method</span>(<span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_enum</span>)

<span class="ruby-comment"># String#split in block form is more memory-effective:</span>
<span class="ruby-identifier">very_large_string</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&quot;|&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">chunk</span><span class="ruby-operator">|</span> <span class="ruby-keyword">return</span> <span class="ruby-identifier">chunk</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">chunk</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-string">&#39;DATE&#39;</span>) }
<span class="ruby-comment"># This could be rewritten more idiomatically with to_enum:</span>
<span class="ruby-identifier">very_large_string</span>.<span class="ruby-identifier">to_enum</span>(<span class="ruby-value">:split</span>, <span class="ruby-string">&quot;|&quot;</span>).<span class="ruby-identifier">lazy</span>.<span class="ruby-identifier">grep</span>(<span class="ruby-regexp">/DATE/</span>).<span class="ruby-identifier">first</span>
</pre>

<p>It is typical to call <a href="Object.html#method-i-to_enum"><code>to_enum</code></a> when defining methods for a generic <a href="Enumerable.html"><code>Enumerable</code></a>, in case no block is passed.</p>

<p>Here is such an example, with parameter passing and a sizing block:</p>

<pre class="ruby"><span class="ruby-keyword">module</span> <span class="ruby-constant">Enumerable</span>
  <span class="ruby-comment"># a generic method to repeat the values of any enumerable</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">repeat</span>(<span class="ruby-identifier">n</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;#{n} is negative!&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">n</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>
      <span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span>(<span class="ruby-identifier">__method__</span>, <span class="ruby-identifier">n</span>) <span class="ruby-keyword">do</span> <span class="ruby-comment"># __method__ is :repeat here</span>
        <span class="ruby-identifier">sz</span> = <span class="ruby-identifier">size</span>     <span class="ruby-comment"># Call size and multiply by n...</span>
        <span class="ruby-identifier">sz</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">n</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">sz</span>  <span class="ruby-comment"># but return nil if size itself is nil</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-operator">*</span><span class="ruby-identifier">val</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">n</span>.<span class="ruby-identifier">times</span> { <span class="ruby-keyword">yield</span> <span class="ruby-operator">*</span><span class="ruby-identifier">val</span> }
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-node">%i[hello world]</span>.<span class="ruby-identifier">repeat</span>(<span class="ruby-value">2</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span> <span class="ruby-identifier">puts</span> <span class="ruby-identifier">w</span> }
  <span class="ruby-comment"># =&gt; Prints &#39;hello&#39;, &#39;hello&#39;, &#39;world&#39;, &#39;world&#39;</span>
<span class="ruby-identifier">enum</span> = (<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">14</span>).<span class="ruby-identifier">repeat</span>(<span class="ruby-value">3</span>)
  <span class="ruby-comment"># =&gt; returns an Enumerator when called without a block</span>
<span class="ruby-identifier">enum</span>.<span class="ruby-identifier">first</span>(<span class="ruby-value">4</span>) <span class="ruby-comment"># =&gt; [1, 1, 1, 2]</span>
<span class="ruby-identifier">enum</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment"># =&gt; 42</span>
</pre>

                              <div class="method-source-code" id="to_enum-source">
            <pre>static VALUE
obj_to_enum(int argc, VALUE *argv, VALUE obj)
{
    VALUE enumerator, meth = sym_each;

    if (argc &gt; 0) {
        --argc;
        meth = *argv++;
    }
    enumerator = rb_enumeratorize_with_size(obj, meth, argc, argv, 0);
    if (rb_block_given_p()) {
        enumerator_ptr(enumerator)-&gt;size = rb_block_proc();
    }
    return enumerator;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Object.html#method-i-enum_for">enum_for</a>
                            </div>

                          </div>

                  <div id="method-i-to_s" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_s    &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a string representing <em>obj</em>. The default <a href="Object.html#method-i-to_s"><code>to_s</code></a> prints the object’s class and an encoding of the object id. As a special case, the top-level object that is the initial execution context of Ruby programs returns “main”.</p>

                              <div class="method-source-code" id="to_s-source">
            <pre>VALUE
rb_any_to_s(VALUE obj)
{
    VALUE str;
    VALUE cname = rb_class_name(CLASS_OF(obj));

    str = rb_sprintf(&quot;#&lt;%&quot;PRIsVALUE&quot;:%p&gt;&quot;, cname, (void*)obj);

    return str;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

